package top.hzy520.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.HeaderHttpSessionStrategy;
import org.springframework.session.web.http.HttpSessionStrategy;
import top.hzy520.common.constants.Parameters;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 14:06 2018/7/17
 */
@Configuration
@EnableRedisHttpSession
public class HttpSessionConfig {
    @Autowired
    private Parameters parameters;

    @Bean
    public HttpSessionStrategy httpSessionStrategy(){return new HeaderHttpSessionStrategy();}


    @Bean
    public JedisConnectionFactory connectionFactory(){
        JedisConnectionFactory factory=new JedisConnectionFactory();
        factory.setHostName(parameters.getRedisHost());
        factory.setPort(Integer.valueOf(parameters.getRedisPort()));
        factory.setTimeout(2000);
        return factory;
    }
}
